#include "menu.h"
#include "editor.h"
#include <stdio.h>
#include <stdlib.h>
int menueditor(char gay[100])
{
         menu menu;
          while (menu.opc != 0){
system ("cls");    
printf("\n\n QUE FAREM EN %s \n\n\t1 - <EDITOR> \n\t2 - <LECTOR RAPIDO> \n\t3 - <LECTOR> \n\n\t0 - <ATRAS>\n\nTUX# ",menu.arch);
_flushall();
scanf("%i",&menu.opc);

      
    switch (menu.opc) {
             
      case 1:
           write(&menu);
          break;
          
      case 2:
           leer1(&menu);
          break;
      case 3:
         full_leer(&menu);
          break;

          
      case 0:
          break;
          
      default: 
          system ("cls");
          printf("OPCION ERRONEA\n\n\n");
          system("PAUSE>NULL");      
          break;
    }
system("cls");
}
return (0);
}



void write(menu *m)
{
          system ("cls");
          printf("<EDITOR> \t PRESIONA $ Y ENTER PARA SALIR\n\n\n");
          _flushall();
         printf("ESCRIBE:\n");
          scanf("%[^\$]", m->num);
          
          m->fpointer=fopen( m->arch,"a+");
           if (m->fpointer == NULL){
             printf("NO  \n");
             system("pause>null");
             menuprinci();
             
             }
          fprintf(m->fpointer, "%s\n",m->num);
          fclose(m->fpointer);
             system("PAUSE>NUL");
}

	


void leer1 (menu *m)
{	    
      menu menu;
          system ("cls");
          printf("FIRST READING\n\n\n");
          m->fpointer=fopen(m->arch,"r");
          
          if (m->fpointer == NULL){
             printf("NO AS ESCRITO NADA MEN\n");
             system("PAUSE>NULL");
             exit(-1);
          }
          
          fscanf (m->fpointer, "%s", &m->reading);
          printf("%s\n", m->reading);
          fclose(m->fpointer);
          printf("\n <VOLVER ATRAS>");
          system("PAUSE>null");
}


void full_leer (menu *m)
{
     menu menu;
       system ("cls");
          printf("FULL READING\n\n\n");
          m->fpointer=fopen(m->arch,"r");
          if (m->fpointer == NULL)
              exit(1);
              printf("\nLO QUE HAY DENTRO ES \n\n");
          while (feof(m->fpointer) == 0){
                m->conte = fgetc(m->fpointer);
                printf("%c",m->conte);
          }
          fclose(m->fpointer);
          printf("\n <VOLVER ATRAS>");
          system("PAUSE>NULL");
     }


